package com.xiaodeng.xdblogspringboot.mapper;

import com.xiaodeng.xdblogspringboot.pojo.Application;
import com.xiaodeng.xdblogspringboot.pojo.DTO.ApplicationDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ApplicationMapper {

    //新增申请记录
    @Insert("insert into application (article_id,applicant_id,application_time,audit_reason,audit_status,audit_time,auditor_id)" +
            " values(#{articleId},#{applicantId},#{applicationTime},#{auditReason},#{auditStatus},#{auditTime},#{auditorId})" )
    void application(Application application);
    //审核申请记录
    @Update("update application set audit_status=#{auditStatus},audit_time=#{auditTime},auditor_id=#{auditorId},audit_reason=#{auditReason} where id=#{id}")
    void auditApplication(Application application) ;
    //管理查询申请记录
    List<ApplicationDTO> getAllApplication(@Param("title") String title, @Param("username") String username, @Param("auditStatus") String auditStatus);
    // 用户查询审核的申请记录
    @Select("select * from application a,article b where applicant_id=#{userId} and a.article_id = b.id order by application_time desc")
    List<ApplicationDTO> getApplication(@Param("userId") Integer userId);



}
